using System;
using System.Collections.Generic;
using System.Text;
using Dune.Business.Domain.Users;
using Edge.Common.Services;
using Edge.DAL.Common;
using Edge.DAL.Managers;

namespace Dune.DAL.Managers
{
    class InviteManager : AbstractManager<Invite, string, User>, IInviteManager
    {
        public bool SetInvite(Invite invite, User user, User newUser)
        {
            using (IDalOperation op = CreateSaveOperation())
            {
                try
                {
                    Session.Save(newUser);
                    newUser = Locator.GetService<IUserManager>().GetContactByMail(newUser.Email);
                    Session.Save(invite);
                    user.InvitesNumber--;
                    Session.Update(user);
                    op.Commit();
                    return true;
                }
                catch (Exception err)
                {
                    op.Dispose();
                    return false;
                }
            }
            
        }
    }
}
